// 上下课
const startEndCourseMixin = {
	data(){
		return{
			//是否下课
			isEnd: false,
		}
	},
	methods:{
		// 初始化上下课状态
		getEndInfo(data){
			this.isEnd = data.isOver;
		},
		// 下课
		async endCourse(){
			let that = this
			if(!that.isEnd){
				// 如果要下课, 需要确认一下
				uni.showModal({
					title: '确认下课吗?',
					content: '再次点击可以恢复哦',
					confirmColor: '#f44336',
					success(e) {
						if(e.confirm){
							that.changeCourseStatus()
						}
					}
				})
			}else{
				that.changeCourseStatus()
			}
		},
		// 更改课程状态 上课,下课
		async changeCourseStatus(){
			await this.$http.request({
				url: 'api/LivePush/SetOver',
				method: 'POST',
				data:{
					id: this.id,
					classId: this.classId,
					isOver: !this.isEnd
				}
			})
			await this.socket.sendSocketMessage('0004', {
				id: this.id,
				classId: this.classId,
				isOver: !this.isEnd
			})
			if(this.isEnd){
				this.livePushInfo.livePlayUrl = ''
			}else{
				this.livePushInfo.livePlayUrl = this.bkLivePlayerUrl;
			}
		}
	}
}

export default startEndCourseMixin;